package com.example.controller;

import com.example.domain.User;
import com.example.dto.UserChangePasswordDTO;
import com.example.dto.UserUpdateDTO;
import com.example.service.LibraryService;
import com.example.service.UserService;
import com.example.util.Result;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName:UserController
 * Package:com.example.controller
 * User:HP
 * Date:2025/8/23
 * Time:下午4:10
 * Author 周东汉
 * Version 1.0
 * Description:
 */
@Slf4j
@RestController
@PreAuthorize("hasRole('ROLE_USER')")
@RequestMapping("/api/user")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("/info")
    public Result getUserInfo() {
        return userService.getUserById();
    }

    @PostMapping("/update")
    public Result updateUserInfo(@RequestBody @Valid UserUpdateDTO userUpdateDTO) {
        return userService.updateUserInfo(userUpdateDTO);
    }

    @PostMapping("/changePassword")
    public Result changePassword(@RequestBody @Valid UserChangePasswordDTO userChangePasswordDTO) {
        return userService.changePassword(userChangePasswordDTO.getUserId(), userChangePasswordDTO.getOldPassword(), userChangePasswordDTO.getNewPassword());
    }


}
